<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/23 0023
 * Time: 下午 3:16
 */

namespace app\moonlighting\controller;

use app\sports_admin\model\Grade as GradeModel;
use app\sports_admin\model\Plan as PlanModel;
use app\sports_admin\model\SportProject as SportProjectModel;
use app\sports_admin\service\PlayType as PlanTypeService;

use think\Request;

class Plan extends Base
{
    public function index()
    {
        return view('index');
    }

    public function add()
    {
        //获取年级信息
        $grade = GradeModel::field('id,grade_title')->select();
        //运动类别id
        $project = SportProjectModel::field('id,title')->select();
        //分类信息
        $data = PlanTypeService::index();
        return view('add',compact('grade','project','data'));
    }

    public function edit(Request $request)
    {
        $id = $request->get('id');
        //运动类别id
        $project = SportProjectModel::field('id,title')->select();
        //获取年级信息
        $grade = GradeModel::field('id,grade_title')->select();
        //获取教案类别
        $type = PlanTypeService::index();
        $info = PlanModel::where('id',$id)->find()->toArray();
        $oneImg = $info['start_part']['one_imgs'];
        $twoImg = $info['preparation_part']['two_imgs'];
        $imgStr = $info['basic_part']['str_img'];
        unset($info['start_part']['one_imgs']);
        unset($info['preparation_part']['two_imgs']);
        unset($info['basic_part']['str_img']);
        return view('edit',compact('info','type','grade','imgStr','oneImg','twoImg','project'));
    }
}